<?php 


require "../common/Curl.php";

/**
 *	https://open.esign.cn/doc/detail?id=opendoc%2Fpaas_api%2Fox6nog&namespace=opendoc%2Fpaas_api
 * 	电子签名SaaS API非标版
 * 	个人签署账号API----接口顺序排列封装
 * 
 */

$appId = "7438873193";       //应用id
$secret = "1dc4d84aeeb9698c29c57202485581b5";  //应用密钥
$grantType = "client_credentials";   //授权类型，固定值
$url = "https://smlopenapi.esign.cn";  // url沙箱环境

$token = getTokenEnd($appId,$secret,$grantType);  // 直接返回token值


$header = array(                          // header请求头信息
        'X-AjaxPro-Method:ShowList',
        'User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36',
        'X-Tsign-Open-App-Id:'.$appId,
		'Content-Type:application/json',
		'charset=UTF-8',
		'X-Tsign-Open-Token:'.$token
    );



$thirdPartyUserId = "15179798856";  //唯一标识
$name = "刘颂晶";
$idType = "CRED_PSN_CH_IDCARD";  //大陆身份证
$idNumber = "360731199907050379";
$mobile = "15179798856";
$email = "1937318982@qq.com";

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [createByThirdPartyUserId 创建个人签署账号  手机和邮箱最好也填，全参数填写]      有用
 * @param  [type] $thirdPartyUserId [创建个人账号的唯一标识。可将个人证件号、手机号、邮箱地址等作为此账号的唯一标识。]
 * @param  [type] $name             [姓名]
 * @param  [type] $idNumber         [证件号，请传入真实的证件信息]
 * @param  [type] $mobile           [手机号码，默认空。]
 * @param  string $idType           [证件类型，默认CRED_PSN_CH_IDCARD]
 * @param  [type] $email            [邮箱地址，默认空。]
 * @return [json]                   [个人账号accountId]
 */
function createByThirdPartyUserId($thirdPartyUserId,$name,$idNumber,$mobile,$idType,$email,$header,$url="https://smlopenapi.esign.cn"){
	$data = [
		"thirdPartyUserId"=>$thirdPartyUserId,
	    "name"=>$name,
	    "idType"=>$idType,
	    "idNumber"=>$idNumber,
	    "mobile"=>$mobile,
	    "email"=>$email
	];
	$header = $header;
	$get_url = $url."/v1/accounts/createByThirdPartyUserId";
	$res = send_request($get_url, $method = "POST", $data, $header);
	return $res['data'];
}
$a = createByThirdPartyUserId($thirdPartyUserId,$name,$idNumber,$mobile,$idType,$email,$header);
var_dump($a);
die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
 * [updateByAccountId 根据accountId修改个人签署账号 唯一标识确定，其他参数选择修改]  有用
 * @param  [type] $accountId [创建账号返回的accountId]
 * @param  [type] $name      [姓名]
 * @param  [type] $idNumber  [证件号，请传入真实的证件信息]
 * @param  [type] $mobile    [手机]
 * @param  [type] $idType    [证件类型，默认CRED_PSN_CH_IDCARD]
 * @param  [type] $email     [邮箱]
 * @param  [type] $header    [请求头]
 * @param  string $url       [请求地址]
 * @return [json]            [返回修改后账号信息]
 */
function updateByAccountId($accountId,$name,$idNumber,$mobile,$idType,$email,$header,$url="https://smlopenapi.esign.cn"){
	$get_url = $url."/v1/accounts/".$accountId;
	$data = [
		'name'=>$name,
		"idType"=>$idType,
	    "idNumber"=>$idNumber,
	    "mobile"=>$mobile,
	    "email"=>$email
	];
	$header = $header;
	$res = send_request($get_url, $method = "PUT", $data, $header);
	return $res['data'];
}
// $accountId = "01ca76230fb640f989616c2d4f29feaf";
// $name = 'liusongjing111';
// $a = updateByAccountId($accountId,$name,$idNumber,$mobile,$idType,$email,$header);
// var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [updateByThirdId 根据thirdPartyUserId修改个人签署账号 唯一标识确定，其他参数选择修改]  有用
 * @param  [type] $thirdPartyUserId [创建个人账号的唯一标识。可将个人证件号、手机号、邮箱地址等作为此账号的唯一标识。]
 * @param  [type] $name             [姓名]
 * @param  [type] $idNumber         [证件号，请传入真实的证件信息]
 * @param  [type] $mobile           [手机]
 * @param  [type] $idType           [证件类型，默认CRED_PSN_CH_IDCARD]
 * @param  [type] $email            [邮箱]
 * @param  [type] $header           [请求头]
 * @param  string $url              [请求地址]
 * @return [json]                   [返回修改后账号信息]
 */
function updateByThirdId($thirdPartyUserId,$name,$idNumber,$mobile,$idType,$email,$header,$url="https://smlopenapi.esign.cn"){
	$get_url = $url."/v1/accounts/updateByThirdId?thirdPartyUserId=".$thirdPartyUserId;
	$data = [
		'name'=>$name,
		"idType"=>$idType,
	    "idNumber"=>$idNumber,
	    "mobile"=>$mobile,
	    "email"=>$email
	];
	$header = $header;
	$res = send_request($get_url, $method = "POST", $data, $header);
	return $res['data'];
}
// $thirdPartyUserId = "15179798856";
// $name = 'liusongjing';
// $a = updateByThirdId($thirdPartyUserId,$name,$idNumber,$mobile,$idType,$email,$header);
// var_dump($a);die;


//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
 * http://localhost/lsjeqb/b2c/person.php   有用
 * [selectAccountId 通过accountIdID查询个人信息 就是创建完个人账号返回的数据accountID]
 * @param  [type] $accountId [个人签署账号ID]
 * @param  [type] $header    [请求头]
 * @param  string $url       [沙箱环境]
 * @return [json]            [个人账号信息]
 */
function selectAccountId($accountId,$header,$url="https://smlopenapi.esign.cn"){
	$url = $url."/v1/accounts/".$accountId;
	$head = $header;
	$res = get($url,$head);
	return $res;
}
// $accountId = "01ca76230fb640f989616c2d4f29feaf";
// $a = selectAccountId($accountId,$header);
// var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
 * http://localhost/lsjeqb/b2c/person.php   有用
 * [selectThirdPartyUserId 通过thirdPartyUserId查询个人信息 就是创建时的个人唯一标识thirdPartyUserId]
 * @param  [type] $thirdPartyUserId [个人唯一标识]
 * @param  [type] $header    [请求头]
 * @param  string $url       [沙箱环境]
 * @return [json]            [个人账号信息]
 */
function selectThirdPartyUserId($thirdPartyUserId,$header,$url="https://smlopenapi.esign.cn"){
	$url = $url."/v1/accounts/getByThirdId?thirdPartyUserId=".$thirdPartyUserId;
	$head = $header;
	$res = get($url,$head);
	return $res;
}
// $thirdPartyUserId = "15179798856";
// $a = selectThirdPartyUserId($thirdPartyUserId,$header);
// var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------




/**
 * [deleteByAccountId 用acccountId删除个人账户]   有用   curlData
 * @param  [type] $accountId [accountId个人账户创建时返回的]
 * @param  [type] $header    [请求头]
 * @param  string $url       [请求地址]
 * @return [json]            [返回成功或者用户不存在]
 */
function deleteByAccountId($accountId,$header,$url="https://smlopenapi.esign.cn"){
	$url = $url."/v1/accounts/".$accountId;
	$header = $header;
	$res = curlData($url, $data='', $header, $method = 'DELETE', $type='json');
	return $res;
}
// $accountId = "b2ecfcc31f6340659ffa034cb4bd4da6";
// $a = deleteByAccountId($accountId,$header);
// var_dump($a);die;

/**
 * [deleteByThirdPartyUserId 根据thirdPartyUserId删除个人账号]    有用   curlData
 * @param  [type] $thirdPartyUserId [thirdPartyUserId个人唯一标识]
 * @param  [type] $header           [请求头]
 * @param  string $url              [请求地址]
 * @return [json]                   [返回成功或者用户不存在]
 */
function deleteByThirdPartyUserId($thirdPartyUserId,$header,$url="https://smlopenapi.esign.cn"){
	$url = $url."/v1/accounts/deleteByThirdId?thirdPartyUserId=".$thirdPartyUserId;
	$header = $header;
	$res = curlData($url, $data='', $header, $method = 'DELETE', $type='json');
	return $res;
}
// $thirdPartyUserId = "15179798856";
// $a = deleteByThirdPartyUserId($thirdPartyUserId,$header);
// var_dump($a);die;














































 ?>